<?php

namespace app\apiadmin\model\behavior;

use app\apiadmin\model\mongoModel;

class ControlMongo extends mongoModel
{

    protected $collection = 'live_control';

    protected $pk = '_id';

    public static function list(array $query = [], array $options = [], int $page = 1)
    {
        if (empty($options)) {
            $options = [
                'sort' => ['_id' => -1],
                'skip' => ($page - 1) * 10,
                'limit' => 10,
            ];
        }
        $model = new static();
        return $model->query($query)->options($options)->select();
    }
    
    public static function total(array $query = [])
    {
        $model = new static();
        if (!empty($query)) {
            return $model->query($query)->count();
        } else {
            return $model->count();
        }
    }

    /**
     * 主键删除记录.
     *
     * @param mixed $id  主键
     *
     * @return bool
     */
    public static function del(string $id = null): bool
    {
        if (empty($id)) {
            return false;
        }

        $model = new static();
        return $model->delete($id);
    }
    
}